import { toast } from "../../../utils/util"
Page({
    data: {
        startTime: '',
        endTime: '',
        dayNightFlag: 0,
        isComponent: false,
        wagesPut:'',
        wagesValue:'',
        wagesId:'',
        isAllDay:false
    },
    onLoad(options){
        console.log(options,'options')
        this.setData({
            isComponent: !!options.isComponent,
            wagesPut:options.type,
            wagesId:options.id,
            wagesValue:options.value
        })
        if(options.type){
            wx.setNavigationBarTitle({
                title:'修改工价'
            })
        }
    },
    onPicker(event) {
        if(this.data.isAllDay){
            toast('请先取消选择全天,在做修改。')
            return
        }
        this.setData({
            [event.currentTarget.dataset.model]: event.detail.value
        })
    },
    onSubmit(){
        const pages = getCurrentPages()
        const page = pages[pages.length-2]
        // 调用上级页面setClockTime方法
        if(this.data.isComponent){
            page.selectComponent('#add-project').setClockTime(this.data.startTime,this.data.endTime,this.data.dayNightFlag)
        }
        else{
            page.setClockTime(this.data.startTime,this.data.endTime,this.data.dayNightFlag)
        }
        wx.navigateBack()
    },
    onChangeNightFlag(event){
        console.log(event)
        this.setData({
            dayNightFlag: Number(event.detail.value)
        })
    },
    // 工价修改
    onWagesInput(event){
        console.log(event,'event')
        this.setData({
            wagesValue:event.detail.value
        })
    },
    // 确定修改工价
    onModifyWages(){
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.emit('modifyWages', {data: this.data.wagesValue});
        setTimeout(()=>{
            wx.navigateBack() 
        },500)
    },
    // 选择全天
    onAllDay(event){
        if(!this.data.isAllDay){
            this.setData({
                isAllDay:true,
                startTime:"00:00",
                endTime:"00:00"
            })
        }else{
            this.setData({
                isAllDay:false,
                startTime:"",
                endTime:""
            })
        }
    }
});